package wisents.wicket.form;

import wisents.api.FormRepresentation;
import wisents.api.FormSubmitter;
import wisents.wicket.WicketPageElement;
import wisents.wicket.form.formelements.WicketFormElement;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * User: paul.szulc
 * Date: Dec 23, 2009
 * Time: 10:08:45 AM
 */
public class WicketFormRepresentation extends WicketPageElement implements FormRepresentation {


    private final List<WicketFormElement> formElements;

    public WicketFormRepresentation(String path) {
        super(path);
        formElements = new ArrayList<WicketFormElement>();
    }

    public final void submitWith(FormSubmitter formSubmitter) {
        formSubmitter.submit(this);
    }

    public final WicketFormRepresentation addFormElement(WicketFormElement formElement) {
        formElements.add(formElement);
        return this;
    }

    public final Collection<WicketFormElement> getFormElements() {
        return new ArrayList<WicketFormElement>(formElements);
    }
}
